package com.jamin.aabill.ui;

import java.util.ArrayList;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.jamin.aabill.R;
import com.jamin.aabill.custom.TopBar;
import com.jamin.aabill.custom.TopBarClickListener;
import com.jamin.aabill.ui.base.BaseViewPagerActivityGroup;
import com.jamin.aabill.utils.AppConstant;
import com.jamin.aabill.utils.Utils;
import com.umeng.analytics.MobclickAgent;
/**
 * 
 * 主入口类,4个SubActivity的Group<br>
 * ClassName:AABillActivityGroup
 *
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-7-24	下午1:22:24
 */
public class AABillActivityGroup extends BaseViewPagerActivityGroup{


	protected TextView t1, t2, t3;// 页卡头标
	TopBar topBar = null;
	//	PathLayout path = null;
	//TAG
	private static final String TAG = "AABillActivityGroup=========wangjieming";
	//TAB切换的VIEW
	//	//TAB底部的按钮
	//	RadioButton mAABillRadio = null;
	//	RadioButton mPersonBillRadio = null;
	//	RadioButton mFriendRadio = null;
	//	RadioButton mSettingRadio = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.aabill_activity_group);
		InitViewPager();
		initView();
	}


	/**
	 * 初始化布局
	 * @method initView
	 * @throws 
	 * @since v1.0
	 */
	private void initView() {
		//TopBar
		topBar = (TopBar) findViewById(R.id.top_bar);
		topBar.setTopBarClickListener(new TopBarClickListener() {
			@Override
			public void rightBtnClick() {
				startActivity(new Intent(AABillActivityGroup.this , CreateCircleActivity.class));
			}
			@Override
			public void leftBtnClick() {
				AABillActivityGroup.this.finish();
			}
			@Override
			public void right2BtnClick() {
			}
		});

	}


	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);

		/**
		 * 由于三个子页面不能正常进入OnResume ，所以在ActivityGroup的Resume时，给子页面发送广播，让子页面刷新数据<br>
		 */
		sendBroadcast(new Intent(AppConstant.BILL_CIRCLE_REFRESH_ACTION));
		Utils.log(TAG, "CircleDetailActivityGroup=========onResume");
	}

	@Override
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}
	/***********************************初始化ViewPager****************************************/

	/**
	 * 初始化ViewPager
	 */
	private void InitViewPager() {
		InitImageView();
		InitTextView();
		mPager = (ViewPager) findViewById(R.id.vPager);
		listViews = new ArrayList<View>();

		//addView CircleDetail
		Intent intent1 = new Intent(AABillActivityGroup.this, SubAACircleActivity.class);
		Window subActivity1 = getLocalActivityManager().startActivity("SubAACircleActivity" , intent1);
		View view1 = subActivity1.getDecorView();

		//addView BillList
		Intent intent2 = new Intent(AABillActivityGroup.this, SubPersonBillActivity.class);
		Window subActivity2 = getLocalActivityManager().startActivity("SubPersonBillActivity" , intent2);
		View view2 = subActivity2.getDecorView();


		//addView CircleMember
		Intent intent3 = new Intent(AABillActivityGroup.this, SubSettingActivity.class);
		Window subActivity3 = getLocalActivityManager().startActivity("SubSettingActivity" , intent3);
		View view3 = subActivity3.getDecorView();

		listViews.add(view1);
		listViews.add(view2);
		listViews.add(view3);
		mPager.setAdapter(new MyPagerAdapter(listViews));
		mPager.setCurrentItem(0);
		mPager.setOnPageChangeListener(new MyOnPageChangeListener());
	}

	/**
	 * 初始化动画
	 */
	private void InitImageView() {
		cursor = (ImageView) findViewById(R.id.cursor);
		bmpW = BitmapFactory.decodeResource(getResources(), R.drawable.group_cursor).getWidth();// 获取图片宽度
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		int screenW = dm.widthPixels;// 获取分辨率宽度
		offset = (screenW / 3 - bmpW) / 2;// 计算偏移量
		Matrix matrix = new Matrix();
		matrix.postTranslate(offset, 0);
		cursor.setImageMatrix(matrix);// 设置动画初始位置

	}



}